package top.mhtools.pigeon.common.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.mhtools.pigeon.common.exception.Result;
import top.mhtools.pigeon.common.exception.Results;
import top.mhtools.pigeon.common.persistence.SendMessageReqDTO;
import top.mhtools.pigeon.common.persistence.SimpleSendMessageReqDTO;
import top.mhtools.pigeon.common.service.SendMessageService;
import top.mhtools.pigeon.ding.dto.DingMessageReqDTO;
import top.mhtools.pigeon.ding.service.support.SimpleSendMessageService;

/**
 * 消息通知平台
 *
 * @author machen
 * @date 2020/4/22 18:34
 */
@Slf4j
@RestController
@RequestMapping("/v1")
@Api(tags = "消息发送服务")
public class SendMessageController {

    @Autowired
    private SendMessageService sendMessageService;

    @Autowired
    private SimpleSendMessageService simpleSendMessageService;

    @PostMapping("/message/send")
    @ApiOperation(value = "发送消息", notes = "通过此接口可以发送各平台类型的消息")
    public Result<Void> sendMessage(@RequestBody SendMessageReqDTO sendMessageReqDTO) {
        sendMessageService.sendMessage(sendMessageReqDTO);
        return Results.success();
    }

    @PostMapping("/simple/message/send")
    @ApiOperation(value = "简单方式发送消息", notes = "消息发送类型较为简单, 但支持发送各平台")
    public Result<Void> sendMessage(@RequestBody SimpleSendMessageReqDTO simpleSendMessageReqDTO) {
        simpleSendMessageService.simpleSendMessage(simpleSendMessageReqDTO);
        return Results.success();
    }

    @PostMapping("/ding/message/send")
    @ApiOperation(value = "发送钉钉机器人消息", notes = "具体参数类型与属性命名与钉钉开放文档一致")
    public Result<Void> sendDingMessage(@RequestBody DingMessageReqDTO dingMessageReqDTO) {
        sendMessageService.sendMessage(dingMessageReqDTO);
        return Results.success();
    }
}
